package com.xyht.medicine_management_system.modules.consumptionPoint.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.consumptionPoint.service.MmsUserConsumptionPointService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户消费积分表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-11
 */
@RestController
@SecretBody
@RequestMapping("/userPoint")
public class MmsUserConsumptionPointController {
    @Resource
    private MmsUserConsumptionPointService mmsUserConsumptionPointService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("获取个人积分")
    @GetMapping("/get")
    public ResponseResult getUserPoint(HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserConsumptionPointService.getUserPoint(userId);
    }

    @ApiModelProperty("获取个人积分记录详情")
    @GetMapping("/detail")
    public ResponseResult userPointDetail(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "status", required = false) Integer status,
                                          @RequestParam(value = "searchStr", required = false) String searchStr,
                                          HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserConsumptionPointService.userPointDetail(pageNum, pageSize, status, searchStr, userId);
    }
}

